package com.zhonghui.modlules.product.eshopService.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.eshop.service.Impl.BaseServiceImpl;
import com.zhonghui.common.eshopDozer.config.IGenerator;
import com.zhonghui.common.eshopEnum.ShopCommonEnum;
import com.zhonghui.common.eshopMapper.StoreCategoryMapper;
import com.zhonghui.common.eshopUtil.CateDTO;
import com.zhonghui.common.util.TreeUtil;
import com.zhonghui.modlules.product.eshopDomain.StoreCategory;
import com.zhonghui.modlules.product.eshopService.StoreCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(
        propagation = Propagation.SUPPORTS,
        readOnly = true,
        rollbackFor = {Exception.class}
)
public class StoreCategoryServiceImpl extends BaseServiceImpl<StoreCategoryMapper, StoreCategory> implements StoreCategoryService {
    private final IGenerator generator;

    public StoreCategoryServiceImpl(IGenerator generator) {
        this.generator = generator;
    }

    public List<CateDTO> getList() {
        LambdaQueryWrapper<StoreCategory> wrapper = new LambdaQueryWrapper();
        wrapper.eq( StoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue() ).orderByAsc( StoreCategory::getSort );
        List<CateDTO> list = this.generator.convert(((StoreCategoryMapper)this.baseMapper).selectList(wrapper), CateDTO.class);
        return TreeUtil.list2TreeConverter(list, 0);
    }
}
